package com.guang.lock.condition.conditionsetdifference;

import com.guang.lock.condition.ConditionSetSleepTest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @Description
 * @Author liguang
 * @Date 2022/10/20/20:47
 */
public class SyncronizedEntryListTest {
    private final static Logger logger = LoggerFactory.getLogger(SyncronizedEntryListTest.class);
    static Object object = new Object();

    public static void main(String[] args) {

        List<Thread> threadList  = new ArrayList<>();

        for (int i = 0; i < 10; i++) {
            Thread thread = new Thread(() -> {
                synchronized (object){
                    try {
                        Thread.sleep(150);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    logger.info("线程执行");
                }
            }, "t" + (i + 1));
            threadList.add(thread);
        }

        logger.info("线程的启动顺序是0-9");
        for (Thread thread : threadList) {
            thread.start();
            logger.info("启动顺序是 0-9，线程ID是：{}",thread.getName());
            try {
                TimeUnit.MICROSECONDS.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}
